/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.utils.scheduled;

import java.util.Date;
import java.util.Timer;

/**
 *
 * @author ECH
 */
public class TSListingServices {
    
    private TKCheckListingAvailability taskCheckListingAvailability = new TKCheckListingAvailability();    
    private Timer expiryServiceTimer = new Timer();
    private boolean expiryServiceRunning = false;
    private Date expiryServiceStartDate;
    private long expiryServiceInterval;
    
    private TKSendListingStats taskSendListingStats = new TKSendListingStats();
    private Timer statsServiceTimer = new Timer();
    private boolean statsServiceRunning = false;
    private Date statsServiceStartDate;
    private long statsServiceInterval;
        
    private TKSendListingBoost taskSendListingBoost = new TKSendListingBoost();
    private Timer boostServiceTimer = new Timer();
    private boolean boostServiceRunning = false;
    private Date boostServiceStartDate;
    private long boostServiceInterval;
    
    
    //CX: expiry check
    
    public void startExpiryCheckService(Date startDate, long interval) {
        try {
            if (!expiryServiceRunning) {
                this.expiryServiceTimer = new Timer();
                this.taskCheckListingAvailability = new TKCheckListingAvailability();
                this.expiryServiceTimer.scheduleAtFixedRate(getTaskCheckListingAvailability(), startDate, interval);
                
                this.setExpiryServiceStartDate(startDate);
                this.setExpiryServiceInterval(interval);
                this.setExpiryServiceRunning(true);
            }                
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void stopExpiryCheckService() {     
        try {   
            expiryServiceTimer.cancel();
            expiryServiceTimer.purge();
            setExpiryServiceRunning(false);
        } catch (Exception ex) {}
    }
    
    
    //CX: listing stats
        
    public void startListingStatsService(Date startDate, long interval) {
        try {
            if (!statsServiceRunning) {
                this.statsServiceTimer = new Timer();
                this.taskSendListingStats = new TKSendListingStats();
                this.statsServiceTimer.scheduleAtFixedRate(this.getTaskSendListingStats(), startDate, interval);
                
                this.setStatsServiceStartDate(statsServiceStartDate);
                this.setStatsServiceInterval(interval);
                this.setStatsServiceRunning(true);
            }                
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
        
    public void stopListingStatsService() {     
        try {   
            statsServiceTimer.cancel();
            statsServiceTimer.purge();
            setStatsServiceRunning(false);
        } catch (Exception ex) {}
    }
        
    
    //CX: listing boost
            
    public void startListingBoostService(Date startDate, long interval) {
        try {
            if (!boostServiceRunning) {
                this.boostServiceTimer = new Timer();
                this.taskSendListingBoost = new TKSendListingBoost();
                this.boostServiceTimer.scheduleAtFixedRate(this.getTaskSendListingBoost(), startDate, interval);
                
                this.setBoostServiceStartDate(statsServiceStartDate);
                this.setBoostServiceInterval(interval);
                this.setBoostServiceRunning(true);
            }                
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
        
    public void stopListingBoostService() {     
        try {   
            boostServiceTimer.cancel();
            boostServiceTimer.purge();
            setBoostServiceRunning(false);
        } catch (Exception ex) {}
    }
    
    
    
    
    
    public Timer getExpiryServiceTimer() {
        return expiryServiceTimer;
    }

    public void setExpiryServiceTimer(Timer expiryServiceTimer) {
        this.expiryServiceTimer = expiryServiceTimer;
    }

    public boolean isExpiryServiceRunning() {
        return expiryServiceRunning;
    }

    public void setExpiryServiceRunning(boolean expiryServiceRunning) {
        this.expiryServiceRunning = expiryServiceRunning;
    }

    public Date getExpiryServiceStartDate() {
        return expiryServiceStartDate;
    }

    public void setExpiryServiceStartDate(Date expiryServiceStartDate) {
        this.expiryServiceStartDate = expiryServiceStartDate;
    }

    public long getExpiryServiceInterval() {
        return expiryServiceInterval;
    }

    public void setExpiryServiceInterval(long expiryServiceInterval) {
        this.expiryServiceInterval = expiryServiceInterval;
    }
    
    public TKCheckListingAvailability getTaskCheckListingAvailability() {
        return taskCheckListingAvailability;
    }

    public void setTaskCheckListingAvailability(TKCheckListingAvailability taskCheckListingAvailability) {
        this.taskCheckListingAvailability = taskCheckListingAvailability;
    }
    
    
    public static void main(String[] argv) {
        TSListingServices listingServices = new TSListingServices();
        listingServices.startExpiryCheckService(new Date(), 20000);
    }

    public TKSendListingStats getTaskSendListingStats() {
        return taskSendListingStats;
    }

    public void setTaskSendListingStats(TKSendListingStats taskSendListingStats) {
        this.taskSendListingStats = taskSendListingStats;
    }

    public Timer getStatsServiceTimer() {
        return statsServiceTimer;
    }

    public void setStatsServiceTimer(Timer statsServiceTimer) {
        this.statsServiceTimer = statsServiceTimer;
    }

    public boolean isStatsServiceRunning() {
        return statsServiceRunning;
    }

    public void setStatsServiceRunning(boolean statsServiceRunning) {
        this.statsServiceRunning = statsServiceRunning;
    }

    public Date getStatsServiceStartDate() {
        return statsServiceStartDate;
    }

    public void setStatsServiceStartDate(Date statsServiceStartDate) {
        this.statsServiceStartDate = statsServiceStartDate;
    }

    public long getStatsServiceInterval() {
        return statsServiceInterval;
    }

    public void setStatsServiceInterval(long statsServiceInterval) {
        this.statsServiceInterval = statsServiceInterval;
    }

    public TKSendListingBoost getTaskSendListingBoost() {
        return taskSendListingBoost;
    }

    public void setTaskSendListingBoost(TKSendListingBoost taskSendListingBoost) {
        this.taskSendListingBoost = taskSendListingBoost;
    }

    public Timer getBoostServiceTimer() {
        return boostServiceTimer;
    }

    public void setBoostServiceTimer(Timer boostServiceTimer) {
        this.boostServiceTimer = boostServiceTimer;
    }

    public boolean isBoostServiceRunning() {
        return boostServiceRunning;
    }

    public void setBoostServiceRunning(boolean boostServiceRunning) {
        this.boostServiceRunning = boostServiceRunning;
    }

    public Date getBoostServiceStartDate() {
        return boostServiceStartDate;
    }

    public void setBoostServiceStartDate(Date boostServiceStartDate) {
        this.boostServiceStartDate = boostServiceStartDate;
    }

    public long getBoostServiceInterval() {
        return boostServiceInterval;
    }

    public void setBoostServiceInterval(long boostServiceInterval) {
        this.boostServiceInterval = boostServiceInterval;
    }

}
